package com.goldsprite.projecttemplategenerator.test;

import org.yaml.snakeyaml.Yaml;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Map;

public class YamlProjectConfig {
	public static class ProjectSettings {
		public String downloadUrl;
		public String outputDirectory;
		public String oldProjectName;
		public String newProjectName;
		public String oldPackageName;
		public String newPackageName;
	}

	public static ProjectSettings loadConfig(String yamlPath) throws Exception {
		Yaml yaml = new Yaml();
		try (InputStream input = new FileInputStream(yamlPath)) {
			Map<String, Object> config = yaml.load(input);

			ProjectSettings settings = new ProjectSettings();
			settings.downloadUrl = (String) config.get("download-url");
			settings.outputDirectory = (String) config.get("output-directory");

			Map<String, Map<String, String>> project = (Map<String, Map<String, String>>) config.get("project");
			Map<String, String> projectName = project.get("project-name");
			Map<String, String> packageName = project.get("package-name");

			settings.oldProjectName = projectName.get("old");
			settings.newProjectName = projectName.get("new");
			settings.oldPackageName = packageName.get("old");
			settings.newPackageName = packageName.get("new");

			return settings;
		}
	}
}
